package uk.ac.bath.domains.mover;

import uk.ac.bath.Logger;
import uk.ac.bath.domains.misc.PulseFood2D;
import uk.ac.bath.domains.misc.FoodSupply;
import uk.ac.bath.base.Point;
import uk.ac.bath.base.Cell;
import uk.ac.bath.base.Space;
import uk.ac.bath.base.CellFactoryIF;
import uk.ac.bath.base.Fitness;
import uk.ac.bath.gui.View;



public class MoverEnvironment extends Environment  {

    public PulseFood2D food;
  //  MoverCell proto;
  
    
    public MoverEnvironment(Space space, PulseFood2D food, CellFactoryIF factory) {
        super(space,factory);
        ((MoverCellFactoryIF)factory).setEnvironment(this);
        this.food = food;
        tweaks.addAll(food.getTweaks());
   //     tweaks.addAll(factory.getTweaks());
    //    tweaks.addAll(RecursiveMachine.tweaks);
    }


    public FoodSupply getFoodSupply() {
        return food;
    }

    public double eatFoodAt(Point loc, double amount) {
        return food.eatFoodAt(loc, amount);
    }

    public double getFoodAt(Point loc) {
        return food.getFoodAt(loc);
    }

    public double[][] getFoodArray() {
        return food.getArray();
    }

    public void replenish() {
        food.replenishFood();
    }

    public Cell createRandomCell() {
        Point p = food.randomPoint();
        if (cellAt(p) != null) {
            return null;
        }
        return factory.createRandomCell(p);
    }

    void moveCell(MoverCell cell) {
        Point to = cell.getPoint();
        Point from = cell.getPrevPoint();

        cellArray[from.getIX()][from.getIY()][from.getIZ()] = null;
        cellArray[to.getIX()][to.getIY()][to.getIZ()] = cell;

    }

    @Override
    public void mutateCell(Cell cell) {
        factory.mutate(cell);
    }

    public View createSimulationView() {
       return new MoverPanel(this);
    }

    @Override
    protected void init() {
       // no action needed to init this simulation
    }

    @Override
    public void nextEvaluation(Fitness fitness) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setLogger(Logger log) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
//
//    @Override
//    protected void setFitness(float fitness) {
//        throw new UnsupportedOperationException("Not supported yet.");
//    }
//
//    @Override
//    public void nextEvaluation() {
//        throw new UnsupportedOperationException("Not supported yet.");
//    }

}

